package main

func main() {

	//[1,2,2,null,3,null,3]

	root := &TreeNode{
		Val: 1,
		Left: &TreeNode{
			Val:  2,
			Left: nil,
			Right: &TreeNode{
				Val:  3,
				Left: nil,
			},
		},
		Right: &TreeNode{
			Val:  2,
			Left: nil,
			Right: &TreeNode{
				Val:  3,
				Left: nil,
			},
		},
	}
	println(invertTree(root))
}

func invertTree(root *TreeNode) *TreeNode {

	var invert func(node *TreeNode)

	invert = func(node *TreeNode) {
		if node == nil {
			return
		}

		node.Left, node.Right = node.Right, node.Left

		invert(node.Left)
		invert(node.Right)
	}

	invert(root)
	return root
}

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}
